#include<stdio.h>
#include<unistd.h>

int global_value = 100;

int main(){
    pid_t id = fork();
    if(id < 0){
        printf("fork error\n");
        return 1;
    }
    else if(id == 0){
        printf("child\n");
        int cnt = 0;
        while(1){
            printf("我是子进程，pid：%d，ppid：%d   global：%d，&global：%p\n",getpid(),getppid(),global_value,&global_value);
            sleep(1);
            cnt++;
            if(cnt == 10){
                global_value = 300;
                printf("global_value被子进程修改啦.....\n");
            }
        }
    }
    else {
        printf("parent\n");

        while(1){
            printf("我是父进程，pid：%d，ppid：%d   global：%d，&global：%p\n",getpid(),getppid(),global_value,&global_value);
            sleep(2);
            global_value = 400;
        }
    }
    return 0;
}
